package com.bamboo.tool.entity;

import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * Create by GuoQing
 * Date 2022/1/20 14:46
 * Description
 * @author bamboo
 */
@Data
@ToString
public class ApiMethod implements Serializable {
    /**
     *  方法id
     */
    private String id;
    /**
     * 方法名称
     */
    private String methodName = StringUtils.EMPTY;

    /**
     * 方法URL
     */
    private String methodUrl = StringUtils.EMPTY;
    /**
     * 请求类型
     */
    private Set<String> requestMethods = new HashSet<>();

    /**
     * 方法参数
     */
    private String methodParams = StringUtils.EMPTY;

    /**
     * 方法其它信息
     */
    private MethodOtherInfo otherInfo = new MethodOtherInfo();

    /**
     * method 持久化
     */
    private MethodPersistenceInfo persistence = new MethodPersistenceInfo();
    /**
     * 注释集合
     */
    private Map<String, String> desc = new HashMap<>();

    public String toInsertSql(String projectId, String classId) {
        return new StringBuilder().append("insert into bamboo_method (id, project_id, method_name, class_id,method_params,method_url,request_methods,description,persistence,other_info) VALUES(")
                .append("'").append(id).append("',")
                .append("'").append(projectId).append("',")
                .append("'").append(methodName).append("',")
                .append("'").append(classId).append("',")
                .append("'").append(methodParams).append("',")
                .append("'").append(methodUrl).append("',")
                .append("'").append(JSONObject.toJSON(requestMethods)).append("',")
                .append("'").append(JSONObject.toJSON(desc)).append("',")
                .append("'").append(JSONObject.toJSON(persistence)).append("',")
                .append("'").append(otherInfo == null ? "" : JSONObject.toJSON(otherInfo))
                .append("');").toString();

    }
}
